﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SPI_TOOLS.Models
{
    public class DatabaseConnection : INotifyPropertyChanged
    {
        private string _server = "localhost";
        private string _database = "";
        private string _userId = "root";
        private string _password = "root";
        private int _port = 3306;

        public string Server
        {
            get => _server;
            set { _server = value; OnPropertyChanged(nameof(Server)); }
        }

        public string Database
        {
            get => _database;
            set { _database = value; OnPropertyChanged(nameof(Database)); }
        }

        public string UserId
        {
            get => _userId;
            set { _userId = value; OnPropertyChanged(nameof(UserId)); }
        }

        public string Password
        {
            get => _password;
            set { _password = value; OnPropertyChanged(nameof(Password)); }
        }

        public int Port
        {
            get => _port;
            set { _port = value; OnPropertyChanged(nameof(Port)); }
        }

        public string ConnectionString =>
            $"Server={Server};Port={Port};Database={Database};Uid={UserId};Pwd={Password};";

        public event PropertyChangedEventHandler? PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    // Models/TableInfo.cs
    public class TableInfo
    {
        public string TableName { get; set; } = string.Empty;
        public string TableSchema { get; set; } = string.Empty;
        public string TableType { get; set; } = string.Empty;
        public long? TableRows { get; set; }
        public DateTime? CreateTime { get; set; }
        public DateTime? UpdateTime { get; set; }
    }

    // Models/ColumnInfo.cs
    public class ColumnInfo
    {
        public string ColumnName { get; set; } = string.Empty;
        public string DataType { get; set; } = string.Empty;
        public string IsNullable { get; set; } = string.Empty;
        public string ColumnKey { get; set; } = string.Empty;
        public string ColumnDefault { get; set; } = string.Empty;
        public string Extra { get; set; } = string.Empty;
        public Int64? CharacterMaximumLength { get; set; }
        public string ColumnComment { get; set; } = string.Empty;
    }

    // Models/TableData.cs
    public class TableData
    {
        public List<Dictionary<string, object>> Rows { get; set; } = new();
        public List<string> ColumnNames { get; set; } = new();
    }
}
